package com.jerp.ui.main;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import org.zkoss.bind.annotation.NotifyChange;
import org.zkoss.util.resource.Labels;

public class HeaderModel {
	public static final String LANG_KEY = "language";

	private List<Locale> languages;
	private List<MenuItem> menuBar;
	private int sltedInx;

	public List<MenuItem> getMenuBar() {
		if (menuBar == null) {
			menuBar = createMenubar();
		}
		return menuBar;
	}

	private List<MenuItem> createMenubar() {
		List<MenuItem> menuBar = new ArrayList<MenuItem>();

		return menuBar;
	}

	public void setMenuBar(List<MenuItem> menuBar) {
		this.menuBar = menuBar;
	}

	@NotifyChange("selectedLoc")
	public List<Locale> getLanguages() {
		if (languages == null) {
			@SuppressWarnings("unchecked")
			Map<String, Object> langMap = (Map<String, Object>) Labels
					.getSegmentedLabels().get(LANG_KEY);
			languages = new ArrayList<Locale>();
			int i = 0;
			for (String key : langMap.keySet()) {
				Locale loc = new Locale(key);
				languages.add(loc);
				if (key.equals(Locale.ENGLISH.getLanguage())) {
					sltedInx = i;
				}
				i++;
			}
		}
		return languages;
	}

	public int getSltedInx() {
		return sltedInx;
	}

	public void setSltedInx(int sltedInx) {
		this.sltedInx = sltedInx;
	}

}
